package com.twu.biblioteca.session.actions;

import com.twu.biblioteca.Customer;
import com.twu.biblioteca.session.Session;
import com.twu.biblioteca.session.SessionAction;
import com.twu.biblioteca.session.SessionOption;

public class LoginAction extends SessionAction{

    public LoginAction(SessionOption option, Session session) {
        super(option, session);
    }

    @Override
    public String[] getActionInput() {
        return this.getSession().getUi().readLogin();
    }

    @Override
    public void performAction(String[] args) {

        for (Customer customer : this.getSession().getLibrary().getCustomers()) {
            if (customer.getLibraryNumber().equals(args[0]) && customer.getPassword().equals(args[1])) {
                this.getSession().setCurrentlyLoggedIn(customer);
                this.getSession().getUi().successLogin();
                this.getSession().printOptions();
                return;
            }
        }
        this.getSession().getUi().invalidLogin();
    }
}
